package control.hall
{
	import core.Control;
	import core.Model;
	import core.View;
	
	import global.GameState;
	
	import model.load.XmlLoadMessage;
	
	import view.components.HintImgButton;
	import view.hall.Hall;
	import view.login.GameServerLogining;

	public class HallControl
	{
		private var _view:View = View.getInstance();
		private var _model:Model = Model.getInstance();
		private var _control:Control = Control.getInstance();
		private var hintBut:HintImgButton;
		
		public function HallControl()
		{
			initHall();
		}
		
		private function initHall():void
		{
			_view.hallLayer = new Hall();
			_view.gameServerLoginingLayer = new GameServerLogining();
		}
		
		public function switchToFastEnterHint():void
		{
			_view.hallLayer.fastBut.startHint();
			_view.hallLayer.enterBut.stopHint();
			
			hintBut = _view.hallLayer.fastBut;
		}
		
		public function switchToEnterHint():void
		{
			_view.hallLayer.enterBut.startHint();
			_view.hallLayer.fastBut.stopHint();
			
			hintBut = _view.hallLayer.enterBut;
		}
		
		public function stopAllHint():void
		{
			_view.hallLayer.fastBut.stopHint();
			_view.hallLayer.enterBut.stopHint();
		}
		
		public function startOrigalHint():void
		{
			if (hintBut)
			{
				hintBut.startHint();
			}
		}
		
		public function onFastEnter():void
		{
			var xmlMessage:XmlLoadMessage = new XmlLoadMessage(onFastEnterBack);
			var url:String = GameState.getServerLink() + "22&key=" + GameState.snsKey;
			xmlMessage.url = url;
			xmlMessage.send();
		}
		
		private function onFastEnterBack(xml:XML,id:int):void
		{
			
			
			var serverIp:String = String(xml.@serverIp);
			var port:int = int(xml.@port);
			var roomId:String = String(xml.@id);
			
			if (port == -1)
			{
				_control.alertButPanelControl.alert("现在没有适合你的房间！",null);
				return;
			}
			
			GameState.isQuickGame = 1;
			_model.loginModel.loginGameServer(roomId,serverIp,port);
		}
	}
}